var useMultiMessage;
var sound;

function init() {
	_initHeader();
	
	var array = new Array();
	
	array.push("addNotification");
	array.push("removeNotification");
	array.push("getUnreadNotifications");
	array.push("useImmediateForegroundNotification");
	array.push("deleteUnreadNotification");
	array.push("deleteAllUnreadNotifications");
	
	draw_list(array);
}

function setOnListClickHandler(idx) {
	switch(idx) {
		case 0 :
			testAddNotification();
			
		break;
		
		case 1 :
			testRemoveNotification();
			
		break;
		
		case 2 :
			testGetUnreadNotifications();
			
		break;
		
		case 3 :
			testUseImmediateForegroundNotification();
			
		break;
		
		case 4 :
			testDeleteUnreadNotification();
			
		break;
		
		case 5 :
			testDeleteAllUnreadNotifications();
			
		break;
		
		default :

		break;
	}
}

function testAddNotification() {
	var selection = {
		"items" : [
				"true", "false"
		],
		"defValue" : 0,
		"callback" : "soundSelectCallback",
		"title" : "sound",
		"x" : 100,
		"y" : 100
	};
	
	platformUIComponent.showSingleSelect(selection);
}

function testRemoveNotification() {
	var id = prompt("ID", 0);
	
	if(id != null)
		localNotification.removeNotification(Number(id));
}

function testGetUnreadNotifications() {
	localNotification.getUnreadNotifications(getUnreadNotificationsCallback);
}

function testUseImmediateForegroundNotification() {
	var selection = {
		"items" : [
				"true", "false"
		],
		"defValue" : 0,
		"callback" : "useImmediateForegroundNotificationSelectCallback",
		"title" : "useImmediateForegroundNotification",
		"x" : 100,
		"y" : 100
	};
	
	platformUIComponent.showSingleSelect(selection);
}

function testDeleteUnreadNotification() {
	var index = prompt("index", 0);
	
	if(index != null)
		localNotification.deleteUnreadNotification(Number(index));
}

function testDeleteAllUnreadNotifications() {
	notifySuccess("deleteAllUnreadNotifications");
	
	localNotification.deleteAllUnreadNotifications();
}

function getUnreadNotificationsCallback(notifications) {
	if(notifications.length == 0)
		alert("No data");
	else {
		var result = "";
		for( var i = 0; i < notifications.length; i++) {
			result += "index = " + i + "\n";
			result += JSON.stringify(notifications[i]) + "\n";;
		}
		
		alert(result);
	}
}

function useImmediateForegroundNotificationSelectCallback(index) {
	if(index == 0)
		localNotification.useImmediateForegroundNotification(true);
	else
		localNotification.useImmediateForegroundNotification(false);
}

function soundSelectCallback(index) {
	if(index == 0)
		sound = true;
	else
		sound = false;
	
	var selection = {
		"items" : [
				"true", "false"
		],
		"defValue" : 0,
		"callback" : "useMultiMessageSelectCallback",
		"title" : "useMultiMessage",
		"x" : 100,
		"y" : 100
	};
	
	platformUIComponent.showSingleSelect(selection);
}

function useMultiMessageSelectCallback(index) {
	if(index == 0)
		useMultiMessage = true;
	else
		useMultiMessage = false;
	
	var today = new Date();
	var day = today.getDate();
	var month = today.getMonth() + 1;
	var year = today.getFullYear();
	var hour = today.getHours();
	var minute = today.getMinutes();
	var seconds = today.getSeconds();
	var ampm = "am";
	var id = 0;
	var badge = 1;
	var dialogType = "confirm";
	
	if(hour >= 12) {
		ampm = "pm";
		hour = hour - 12;
	}
	
	ampm = prompt("am|pm", ampm);
	if(ampm == null)
		return;
	hour = prompt("hour", hour);
	if(hour == null)
		return;
	minute = prompt("minute", minute);
	if(minute == null)
		return;
	seconds = prompt("seconds", seconds);
	if(seconds == null)
		return;
	id = prompt("ID", id);
	if(id == null)
		return;
	id = Number(id);
	
	badge = prompt("badge", badge);
	if(badge == null)
		return;
	badge = Number(badge);
	dialogType = prompt("dialogType|alert", dialogType);
	if(dialogType == null)
		return;
	
	var time = {
		"year" : year,
		"month" : month,
		"date" : day,
		"hour" : hour,
		"ampm" : ampm,
		"minute" : minute,
		"second" : seconds
	};
	
	var action = {
		"pageId" : "notificationResult",
		"parameters" : {
			"paramKey" : "valueValue",
		},
		"useMultiMessages" : true,
		"title" : "Notification Title",
		"alert" : "Notification Content",
		"dialogType" : dialogType,
		"aps" : {
			"sound" : sound,
			"badge" : badge,
			"alert" : "Notification Content"
		}
	};
	
	localNotification.addNotification(id, time, action);
}